home *** CD-ROM | disk | FTP | other *** search
/ HamCall (April 1991) / HAMCALL CD-ROM (Buckmaster)(April 1991).BIN / amateur / bbsqth / osqth.c < prev    next >
Text File  |  1990-10-14  |  8KB  |  350 lines

  1. /*
  2. OS QTH function for WA7MBL BBS and Buckmaster Publishing HAM CD ROM
  3.  
  4. Syntax:
  5. OSQTH <port#> <call of requestor> QTH call1 call2 call2...
  6.  
  7. Where <port#> is a single char in the range 1-8 and indicates
  8. the port # where the reply is to be sent.  If ECHO is on, the reply
  9. will also appear on the display.  This data is automatically stuffed by the
  10. WA7MBL OS function.  To run from the BBS type:
  11.  
  12. >OS QTH WA4ONG N1BIC ...
  13.  
  14. And the reply will be sent back to the same port requesting it.  The
  15. OS function CANNOT be run from the local SYSOP screen.
  16.  
  17. This code and all associated data may be freely exchanged for non-pecuniary
  18. purposes.  Services or efforts that compete in any way with services or
  19. products offered commercially by Buckmaster are expressly forbidden.
  20.  
  21.  
  22. WA4ONG
  23. */
  24.  
  25. #include <io.h>
  26. #include <fcntl.h>
  27. #include <stdio.h>
  28. #include <time.h>
  29. #include <math.h>
  30. char            CR = 0x0D;
  31. char                        echo;
  32. int                            dpm[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  33. char            bigst[255], filename[90], sucess, ports[8], dfilepath[80],
  34.                                 lfilepath[80], DV;
  35. long            size, low, high, middle, records, number;
  36. FILE           *config, *calls, *logfile;
  37.  
  38. extern unsigned _heaplen = {2000};
  39. extern int directvideo = {0};
  40.  
  41.  
  42. #include "os.h"
  43.  
  44.  
  45. main(int argc, char *argv[])
  46. {
  47.     int             i;
  48.     int             ch, result;
  49.     long            secs;
  50.     char           *asc_time,temp[20];
  51.     if (argc < 3)
  52.         return (1);
  53.  
  54.     config = fopen("oscfg.bin", "r");
  55.     if (config == NULL) {
  56.         fclose(config);
  57.         printf("OS QTH config file ""OSCFG.BIN"" open failed!\n");
  58.         return (1);
  59.     }
  60.     fread(&DV,1,1,config);
  61.     fread(&echo,1,1,config);
  62.     fread(ports,8,1,config);
  63.     fread(dfilepath,80,1,config);
  64.     fread(lfilepath,80,1,config);
  65.     fclose(config);
  66.     comport = atoi(argv[1]) - 1;
  67.     sprintf(filename, "%sport%.1ios.log", lfilepath,comport + 1);
  68.     logfile = fopen(filename, "a");
  69.     time(&secs);
  70.     fprintf(logfile, "%s request by %s on port %.1i on %s", argv[3], argv[2], comport+1, ctime(&secs));
  71.     if (stricmp("qth", argv[3]) == 0) {
  72.         if (argc < 5) {
  73.             fprintf(logfile, "Too few parameters");
  74.             fclose(logfile);
  75.             return (1);
  76.         }
  77.         sucess = 0;
  78.         chdir("e:\\");
  79.         i = open(dfilepath, O_RDONLY);
  80.         size = filelength(i);
  81.         close(i);
  82.         records = size / 129;
  83.         calls = fopen(dfilepath, "r");
  84.         if (calls == NULL) {
  85.             fclose(calls);
  86.             fprintf(logfile, "CD Rom data file open failed!\n");
  87.             fclose(logfile);
  88.             return (1);
  89.         }
  90.  
  91.         for (i = 4; i < argc; i++) {
  92.             result = get_qth(argv[i], bigst);
  93.             outstr("\n");
  94.             outstr(bigst);
  95.             fprintf(logfile, "%s qth ", argv[i]);
  96.             if (result == 0)
  97.                 fprintf(logfile, "not found\n");
  98.             else
  99.                 fprintf(logfile, "found\n");
  100.         }
  101.         if (sucess != 0) {
  102.             sprintf(bigst, "\nFrom the BUCKMASTER PUBLISHING CD-ROM Directory (c) 1989\n");
  103.             outstr(bigst);
  104.         }
  105.         fclose(calls);
  106.         fclose(logfile);
  107.         fclose(config);
  108.         delay(2000);
  109.         return (0);
  110.     }            /* if qth */
  111.     if (stricmp("time", argv[3]) == 0) {
  112.         sprintf(bigst, "%s", ctime(&secs));
  113.         outstr(bigst);
  114.         fclose(logfile);
  115.         delay(2000);
  116.         return (0);
  117.     }
  118.     sprintf(bigst, "Unknown OS function - %s\n", argv[3]);
  119.     outstr(bigst);
  120.     fclose(logfile);
  121.     delay(2000);
  122.     return (1);
  123. }
  124.  
  125. outstr(char *st)
  126. {
  127.     int             i;
  128.     i = 0;
  129.     if (st[0] == 0)
  130.         return;
  131.     do {
  132.         if (st[i] == 10) {
  133.             outSIO(CR);
  134.             if(echo == 1){
  135.                 putch(CR);
  136.                 putch(10);
  137.             }
  138.         } else {
  139.             outSIO(st[i]);
  140.             if(echo == 1) {
  141.                 putch(st[i]);
  142.             }
  143.         }
  144.     } while (st[++i] != 0);
  145. }
  146.  
  147. int
  148. get_qth(char call[], char buffer[])
  149. {
  150.     int             result;
  151.     char            buff1[10];
  152.     result = search_format(call, buff1);
  153.     if (result == 0) {
  154.         sprintf(buffer, "%s is not a valid call format\n", call);
  155.         return(0);
  156.     }
  157. /*    printf("%.6s",buff1);*/
  158.     result = search_record(buff1);
  159.     if (result != 0) {
  160.         get_frecord(number, buffer);
  161.         sucess++;
  162.         return(1);
  163.     } else
  164.         sprintf(buffer, "%s not found\n", call);
  165.     return(0);
  166. }
  167.  
  168. int
  169. search_format(char call[], char outb[])
  170. {
  171.     int             result, call_length, i;
  172.     call_length = strlen(call);
  173.     if ((call_length < 4) || call_length > 6)
  174.         return (0);
  175.     i = 0;
  176.     result = -1;
  177.     do {
  178.         if ((call[i] & 0x70) == '0')
  179.             result = i;
  180.         i++;
  181.     } while ((i < 7) && (result == -1));
  182.     if ((result < 1) || result > 2)
  183.         return (0);
  184.     strcpy(outb, "      ");
  185.     strcpy(outb, &call[result]);
  186.     i = strlen(outb);
  187.     outb[i] = ' ';
  188.     if (result == 1) {
  189.         outb[4] = ' ';
  190.         outb[5] = call[0];
  191.     }
  192.     if (result == 2) {
  193.         outb[4] = call[0];
  194.         outb[5] = call[1];
  195.     }
  196.     return (1);
  197. }
  198.  
  199. int
  200. search_record(char call[])
  201. {
  202.     char            done, buff[8], gotit;
  203.     int             result;
  204.     low = -1;
  205.     high = records;
  206.     gotit = done = 0;
  207.     do {
  208.         if (high > low + 1)
  209.             middle = (high + low) >> 1;
  210.         else {
  211.             low = middle = high;
  212.             done++;
  213.         }
  214.         get_irecord(middle, buff);
  215.         result = strnicmp(call, &buff[0], 6);
  216.         if (result == 0) {
  217.             done++;
  218.             gotit++;
  219.             number = middle;
  220.         }
  221.         if (result < 0)
  222.             high = middle;
  223.         if (result > 0)
  224.             low = middle;
  225.     } while (done == 0);
  226.     return (gotit);
  227. }
  228.  
  229. get_frecord(long number, char buffer[512])
  230. {
  231.     char            buff[130], fname[12], mi[3], lname[21], jr[5], jrs[2], street[36], city[21]
  232.                                  ,state[3], zip5[6], zip4[6], dot[3], callp[3], calln[2], callsuf[4], class[2]
  233.                                  , temp[4], dob[3];
  234.     float                      aa,bb,dd;
  235.     int                            emon,eday,eyear,edoy,i,done;
  236.     dot[1] = ' ';
  237.     dot[2] = 0;;
  238.     jrs[1] = 0;
  239.     get_record(number, buff);
  240.     strim(&buff[30], 11, fname);
  241.     strim(&buff[41], 1, mi);
  242.     if (mi[0] == 0)
  243.         dot[0] = 0;
  244.     else
  245.         dot[0] = '.';
  246.     strim(&buff[6], 20, lname);
  247.     strim(&buff[26], 4, jr);
  248.     if (jr[0] == 0)
  249.         jrs[0] = 0;
  250.     else
  251.         jrs[0] = ' ';
  252.     strim(&buff[0], 2, callp);
  253.     if (callp[0] == ' ') {
  254.         callp[0] = callp[1];
  255.         callp[1] = 0;
  256.     }
  257.     strim(&buff[2], 1, calln);
  258.     strim(&buff[3], 3, callsuf);
  259.     strim(&buff[126], 1, class);
  260.     strim(&buff[42], 35, street);
  261.     strim(&buff[77], 20, city);
  262.     strim(&buff[97], 2, state);
  263.     strim(&buff[99], 5, zip5);
  264.     strncpy(temp,&buff[116],2);
  265.     temp[2]=0;
  266.     eyear=atoi(temp);
  267.     strncpy(temp,&buff[118],3);
  268.     temp[3]=0;
  269.     edoy=atoi(temp);
  270.     if((eyear%4) == 0)
  271.     dpm[1] = 29;
  272.     else
  273.     dpm[1] = 28;
  274.     i=0;
  275.     done=0;
  276.     eday = edoy;
  277.     do{
  278.         if (eday <= dpm[i]) done=1;
  279.         else eday = eday - dpm[i];
  280.         i++;
  281.     } while (done == 0);
  282.     emon = i;
  283.     strncpy(dob,&buff[114],2);
  284.     dob[2]=0;
  285.     /*
  286.      * zip4[0] = 0; strim(&buff[141],4,&zip4[1]); if(zip4[1] != 0)
  287.      * zip4[0]='-';
  288.      */
  289.     sprintf(buffer, "%s %s%s%s%s%s - %s%s%s %s (%s) %i/%i/%i\n%s\n%s, %s %s\n"
  290.         ,fname, mi, dot, lname, jrs, jr, callp, calln, callsuf, class, dob, emon,
  291.         eday, eyear, street, city, state, zip5);
  292. }
  293. strim(char inb[], int count, char outb[])
  294. {
  295.     char            done;
  296.     int             i;
  297.     done = 0;
  298.     strncpy(outb, inb, count);
  299.     outb[count] = 0;
  300.     i = count;
  301.     do {
  302.         if (outb[--i] == ' ')
  303.             outb[i] = 0;
  304.         else
  305.             done++;
  306.     } while ((i != 0) & (done == 0));
  307. }
  308.  
  309. get_record(long number, char buff[])
  310. {
  311.     fseek(calls, 129 * number, 0);
  312.     if(DV==1){
  313.         DV_Nice();
  314.         DV_Crit();
  315.     }
  316.     dropdtr();
  317.     fread(buff, 129, 1, calls);
  318.     raisedtr();
  319.     if(DV==1){
  320.         DV_Uncrit();
  321.         DV_Nice();
  322.     }
  323. }
  324.  
  325.  
  326.  
  327. get_irecord(long number, char buff[])
  328. {
  329.     char buff1[130];
  330.     fseek(calls, 129 * number, 0);
  331.     if(DV==1){
  332.         DV_Nice();
  333.         DV_Crit();
  334.     }
  335.     dropdtr();
  336.     fread(buff1, 129, 1, calls);
  337.     raisedtr();
  338.     if(DV==1){
  339.         DV_Uncrit();
  340.         DV_Nice();
  341.     }
  342.     buff[0] = buff1[2];
  343.     buff[1] = buff1[3];
  344.     buff[2] = buff1[4];
  345.     buff[3] = buff1[5];
  346.     buff[4] = buff1[0];
  347.     buff[5] = buff1[1];
  348.     buff[6] = 0;
  349. }
  350.